package com.avic.rong.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.avic.rong.bean.CategoryBean;
import com.avic.rong.fragment.CompareFragment;
import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * Creater: Created by wangyz on 2017/1/18.
 * Email: 936804097@qq.com
 */

public class CompareIndicatorAdapter extends FragmentPagerAdapter {

    private String comeSource = "";
    private List<CategoryBean> categoryBeanList = new ArrayList<>();
    public List<CompareFragment> compareFragmentList = new ArrayList<>();


    public CompareIndicatorAdapter(FragmentManager fm, String comeFromSource, List<CategoryBean> tempList) {
        super(fm);
        this.comeSource = comeFromSource;
        this.categoryBeanList = tempList;
        compareFragmentList = new ArrayList<>();
    }

    @Override
    public Fragment getItem(int position) {
        boolean startEnd = false;
        if (position == 0 || position == categoryBeanList.size() - 1) {
            startEnd = true;
        }
        CompareFragment tempCompareFragmen = CompareFragment.newInstance(categoryBeanList.get(position).getCatName(), String.valueOf(categoryBeanList.get(position).getCatId()), comeSource, startEnd);
        try {
//            if (position < compareFragmentList.size()) {
            compareFragmentList.add(position, tempCompareFragmen);
            Logger.i("-------------------adrress:" + position + "-----------" + tempCompareFragmen + "---size:" + compareFragmentList.size());
//            }
        } catch (Exception exe) {

        }
        return tempCompareFragmen;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return categoryBeanList.get(position).getCatName();
    }


    @Override
    public int getCount() {
        return categoryBeanList.size();
    }
}